package org.shj.springboot.controller;

import java.util.List;
import java.util.Map;

import org.shj.springboot.entity.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class UserController {

	@Autowired
	MongoTemplate template;
	
	@RequestMapping(value="/user")
	public String showBlogList(Map<String, Object> model){
		boolean exists = template.collectionExists(Customer.class);
		System.out.println("exists: " + exists);
		if(!exists){
			template.createCollection(Customer.class);
		}
		
		List<Customer> list = template.findAll(Customer.class);
		model.put("searchResults", list);
		return "user/search";
	}
}
